﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Price_Push_Service
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label2.Text = Application.StartupPath.ToString();
        }
        private static WS_Rate.Rate_Manage WSRM = new WS_Rate.Rate_Manage();
        private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            try
            {
                Thread.Sleep(2000);
                string FilePath = e.FullPath.ToString();
                StreamReader sr = new StreamReader(FilePath);
                string Print_Str = sr.ReadToEnd();
                sr.Close();
                File.Delete(FilePath);

                Price_Push.Price_Push PP = new Price_Push.Price_Push();
                PP.PUSH_Control(Print_Str);
                label6.Text = DateTime.Now.ToString();
            }
            catch(Exception ex)
            {
                //MessageBox.Show(ex.Message.ToString());
            }

        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            fileSystemWatcher1.Path = label2.Text.Trim().ToString();
            fileSystemWatcher1.EnableRaisingEvents = true;
            label4.Text = "启动";
        }

        private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            fileSystemWatcher1.EnableRaisingEvents = false;
            label4.Text = "停止";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            label10.Text = "运行中";

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                WSRM.MATCH_CREATE_TRADE();
                label11.Text = "最后一次更新时间：" + DateTime.Now.ToString();
            }
            catch(Exception ex)
            { }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            label10.Text = "停止";
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                WSRM.Match_Modified_Trade();
                label12.Text = "最后一次更新时间：" + DateTime.Now.ToString();
            }
            catch (Exception ex)
            { }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
            label13.Text = "运行中";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            label13.Text = "停止";
        }
    }
}
